package cn.net.shuxing.yifu.mysiteforme.admin.util;

import cn.net.shuxing.yifu.common.util.FileUtil;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;

public class HtmlUtil {

    public static String  getBodyWithoutBodyTag(String htmlStr)
    {
        int startIndex = htmlStr.indexOf("<body>");
        int endIndex = htmlStr.lastIndexOf("</body>");
        String html = htmlStr.substring(startIndex + "<body>".length(), endIndex);
        return html;
    }

    public static String  getBodyWithoutBodyTag(File htmlFile)
    {
        String fileExtName = FileUtil.getFileExtName(htmlFile);
        if (!fileExtName.contains("htm"))
        {
            return "";
        }
        else
        {
            try {
                String htmlStr = FileUtils.readFileToString(htmlFile);
                return getBodyWithoutBodyTag(htmlStr);
            } catch (IOException e) {
                return "";
            }
        }
    }

//    public static void main(String[] args) {
//        File file = new File("C:\\Users\\xiaoye\\Desktop\\1.html");
//        System.out.println(getBodyWithoutBodyTag(file));
//    }
}
